

//js used by friend search part
$(document).ready(function()
{
/* no need here by bo
	var keywordFriendValidate=$("#friend_keyword_form").validate(
	{
		rules:
		{
			q: {required: true, maxlength: 20}
		},
		messages:
		{
			q: {required: "请输入搜索关键字", maxlength: "最多输入20个字符"}
		},
		submitHandler: function() {}
	});
	
	
	$("#friend_keyword_submit").click(function()
	{
		if(keywordFriendValidate.form())
		{
			 window.location.href='friend_list/?uid='+$("#uid").val()+'&q='+$("#q").val();
		}
	})*/
});

//js used by send msg part, add friend
$(document).ready(function()
{	
	//add friend
	$("a[class='add_friend']").click(function()
	{   
		var friendID=$(this).attr("name").split("_")[0];   
		var friendName=$(this).attr("name").split("_")[1]; 
		
		$.ajax(
		{
			type: 'get',
			url: edp_domain_url + 'ajax_log_info/?tiny=1',
			timeout: 5000,
			global:false,
			beforeSend: function()
			{
				$.blockUI(
				{ 
					message: '验证用户...',
					css: { padding:'5px',color:'#CC0000'}
				});
			},
			error: function()
			{
				$.blockUI(
				{ 
					message: '验证出错...',
					css: { padding:'5px',color:'#CC0000'}
				});
				$.unblockUI();
			},
		    success: function(data)
		    { 
				if(data==false)
				{   
					popupLogin($('#PopBox'),'添加好友');                
				}
				else
				{
					popupAddFriend($('#PopBox'),friendID,friendName);
				} 
				$.blockUI(
				{ 
					message: $('#PopBox'),    
					css: 
					{ 
						padding:        0,
						margin:         0,
						top:            '30%', 
		        		left:           '35%', 
						width:          '',
						textAlign:      '', 
						color:          '', 
						border:         '',
						backgroundColor:'',       				
						cursor:         'wait'				        
					 }
				}); 			  			 	 
			}
		}); 
	});
	
	//delete friend
	$("a[class='del_friend']").click(function()
	{   
		var friendID=$(this).attr("name").split("_")[0];   
		var friendName=$(this).attr("name").split("_")[1]; 
		
		$.ajax(
		{
			type: 'get',
			url: edp_domain_url + 'ajax_log_info/?tiny=1',	
			timeout: 5000,
			global:false,
			beforeSend: function()
			{
				$.blockUI(
				{ 
					message: '验证用户...',
					css: { padding:'5px',color:'#CC0000'}
				});
			},
			error: function()
			{
				$.blockUI(
				{ 
					message: '验证出错...',
					css: { padding:'5px',color:'#CC0000'}
				});
				$.unblockUI();
			},
		    success: function(data)
		    { 
				if(data==false)
				{               
					popupLogin($('#PopBox'),'删除好友');                
				}
				else
				{
					popupDelFriend($('#PopBox'),friendID,friendName);
				} 
				$.blockUI(
				{ 
					message: $('#PopBox'),    
					css: 
					{ 
						padding:        0,
						margin:         0,
						top:            '30%', 
		        		left:           '35%', 
						width:          '',
						textAlign:      '', 
						color:          '', 
						border:         '',
						backgroundColor:'',       				
						cursor:         'wait'				        
					 }
				}); 			  			 	 
			}
		}); 
	});
	
	$("a[class='send_msg']").click(function() 
	{
		
		var receiverID=$(this).attr("name").split("_")[0];   
		var receiverName=$(this).attr("name").split("_")[1]; 
		
		$.ajax(
		{
			type: 'get',
			url: edp_domain_url + 'ajax_log_info/?tiny=1',
			timeout: 5000,
			global:false,
			beforeSend: function()
			{
				$.blockUI(
				{ 
					message: '验证用户...',
					css: { padding:'5px',color:'#CC0000'}
				});
			},
			error: function()
			{
				$.blockUI(
				{ 
					message: '验证出错...',
					css: { padding:'5px',color:'#CC0000'}
				});
				$.unblockUI();
			},
		    success: function(data)
		    { 
				if(data==false)
				{               
					popupLogin($('#PopBox'),'发送站内信');                
				}
				else
				{
					pupupSendMsg($('#PopBox'),receiverID,receiverName);
				} 
				$.blockUI(
				{ 
					message: $('#PopBox'), 
					css: 
					{ 
						padding:        0,
						margin:         0,
						top:            '30%', 
		        		left:           '35%', 
						width:          '',
						textAlign:      '', 
						color:          '', 
						border:         '',
						backgroundColor:'',       				
						cursor:         'wait'				        
					 }
				}); 		  			 	 
			}
		}); 
		
	});
});

//js used by search friend
$(document).ready(function()
{
/*  no need here by bo
	var searchFriendValidate=$("#friend_search_form").validate(
	{
		rules:
		{
			friend_account: {required:true, maxlength: 30}
		},
		messages:
		{
			friend_account: {required:"请输入用户的Email或用户名", maxlength: "最多输入30个字符"}
		},
		submitHandler: function() {}
	});
*/			
	$("#friend_search_submit").click(function()
	{
		//if(searchFriendValidate.form())
		//{
			window.location.href= edp_domain_url + 'user_search_result/?q='+$("#friend_account").val();
		//}
	})
});

//js used by invite friend
$(document).ready(function()
{
/*  no need here by bo
	var inviteFriendValidate=$("#friend_invite_form").validate(
	{
		rules:
		{
			friend_email: {required:true, email:true, maxlength: 50, check_email: true},
			vcode: { check_vcode: true }
		},
		messages:
		{
			friend_email: {required:"请输入Email地址", email:"Email格式错误", maxlength: "最多输入50个字符", check_email:'该邮箱地址已经注册'},
			vcode: { check_vcode: "验证码错误" }
		},
		submitHandler: function(form) 
		{
			$(form).Submit();
		}
	});

	jQuery.validator.addMethod("check_vcode", function(value, element) 
	{
		var result=true;
		if(value=='')
			result=false;
		else
		{
			$.ajax(
			{
				type: 'Get',
				url: edp_domain_url + 'ajax_vcode_validate/?tiny=1&code='+value,
				async: false,
				dataType: 'json',
				timeout: 500,
				success: function(data)
				{
					result=data.res;    
				}
			 });
		}
		return result;
	}, "");
	
	//Validate Function to check the email address overlap
	// True表示Email未被占用，false表示被占用
	jQuery.validator.addMethod("check_email", function(value, element) 
	{
		var result=true;
		$.ajax({
			type: 'Get',
			url: edp_domain_url + 'ajax_register_check/?tiny=1&type=email&email='+value,
			async: false,
			dataType: 'json',
			timeout: 1000,
			success: function(data)
			{
				result=data.res;    
			}
		 });
	     return result;
	}, "");
	
*/
});

function refresh_vcode(url){
 
   $("#vimg").attr('src',url);
 
}

$(document).ready(function(){

	LoadSortbyClass();
	
	$("#sort_nick").click(
		function(){
			SetSortBy( "1" )
		}
	);
	
	$("#sort_contribution").click(
		function(){
			SetSortBy( "2" )
		}
	);
	
	
	$("#order_asc").click(
		function(){
			SetOrderBy( "1" )
		}
	);
	
	$("#order_desc").click(
		function(){
			SetOrderBy( "2" )
		}
	);	
		
		
});

function SetSortBy( type ){
	//reset the sort by selector
	
	$( "#sortby" ).val(type);
	$( "#sortform" ).submit();
}

function SetOrderBy( type ){
	//reset the sort by selector
	
	$( "#order" ).val(type);
	$( "#sortform" ).submit();
}

function LoadSortbyClass(){

	var sortby = $( "#sortby" ).val();
  
	if( sortby == '1' ){
	
		$( "#sort_nick" ).replaceWith('<span>'+$( "#sort_nick" ).text()+'</span>');
	}

	if( sortby == '2'  ){
	
		$( "#sort_contribution" ).replaceWith('<span>'+$( "#sort_contribution" ).text()+'</span>');
	}	
}

